import { ConverterBase } from './base';
import { UIOpacity } from './cc';
import { enum_ } from '../../model';

export class SpriteConverter extends ConverterBase {
    public async convert() {
        let name = this.treePSD.get<string>(enum_.Psd.name);
        const nameParts = name.split('.');
        if (nameParts.length > 1)
            name = nameParts[0];

        name = 'sprite-' + name;
        const node = this.createNode({ name });
        const nodeOpacity = this.appendComponent(UIOpacity, node);
        nodeOpacity.opacity = this.treePSD.get<any>(enum_.Psd.image).opacity * 255;
        await this.appendSprite(this.treePSD, node);
        return node;
    }
}